home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 3 / CD ACTUAL 3.iso / linux / incoming / jstools-.6v3 / jstools- / jstools-tk3.6v3.0 / lib / jconfirm.tcl < prev    next >
Encoding:
Text File  |  1995-02-09  |  2.3 KB  |  83 lines

  1. # jconfirm.tcl - (optional) confirmation panel
  2. # Copyright 1992-1994 by Jay Sekora.  All rights reserved, except 
  3. # that this file may be freely redistributed in whole or in part 
  4. # for non-profit, noncommercial use.
  5. # this procedure is required by (at least)
  6. #     browser.tk
  7. #     edit.tk
  8. #     help.tk
  9. #     more.tk
  10. #     people.tk
  11. #     prefs.tk
  12. ######################################################################
  13.  
  14. ### TO DO
  15.  
  16. ######################################################################
  17. # global variables:
  18. #
  19. global J_PREFS env
  20. if {! [info exists J_PREFS(autoposition)]} {set J_PREFS(autoposition) 0}
  21. if {! [info exists J_PREFS(confirm)]} {set J_PREFS(confirm) 1}
  22. #
  23. ######################################################################
  24.  
  25.  
  26. ######################################################################
  27. # j:confirm ?options? - Cancel/OK dialogue box
  28. # options include
  29. #   -title (default "Confirm")
  30. #   -text (default "Are you sure?")
  31. #   -priority (default 0)
  32. #   -yesbutton (default "OK")
  33. #   -nobutton (default "Cancel")
  34. # returns true (1) on OK; false (0) on Cancel
  35. # if (priority == 0 && $J_PREFS(confirm) == 0), the dialogue box is
  36. #   not displayed; it always returns 1
  37. ######################################################################
  38.  
  39. proc j:confirm { args } {
  40.   j:parse_args {
  41.     {title Confirm}
  42.     {priority 0}
  43.     {text "Are you sure?"}
  44.     {yesbutton OK}
  45.     {nobutton Cancel}
  46.   }
  47.   
  48.   global confirm_result
  49.   global J_PREFS            ;# for J_PREFS(confirm)
  50.  
  51.   if { (! $J_PREFS(confirm)) && (! $priority) } {
  52.     return 1
  53.   }
  54.  
  55.   set old_focus [j:current_focus]    ;# so we can restore original focus
  56.  
  57.   toplevel .confirm
  58.   wm title .confirm $title
  59.   
  60.   message .confirm.msg -width 300 -anchor w -text $text
  61.   j:buttonbar .confirm.b -default ok -buttons [format {
  62.     {ok %s {set confirm_result 1; destroy .confirm}}
  63.     {cancel %s {set confirm_result 0; destroy .confirm}}
  64.   } $yesbutton $nobutton]
  65.   
  66.   pack .confirm.msg -side top -fill both -expand yes -padx 10 -pady 10
  67.   pack [j:rule .confirm -width 200] -side top -fill x
  68.   pack .confirm.b -side bottom -fill x
  69.   
  70.   j:dialogue .confirm        ;# position in centre of screen
  71.  
  72.   focus .confirm
  73.   j:default_button .confirm.b.ok .confirm
  74.   j:cancel_button .confirm.b.cancel .confirm
  75.   grab .confirm
  76.   tkwait window .confirm
  77.   focus $old_focus
  78.   return $confirm_result
  79. }
  80.